package com.hzhjhh.view.manageView.menus.storage.inReturnGoods;

import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.util.Vector;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import com.hzhjhh.means.Select_Means;
import com.hzhjhh.view.manageView.menus.storage.InReturnGoodsDialog;

/**
 * 商品编号
 * 
 * @author 12083
 *
 */
public class MerchandiseCode {

	/**
	 * 标签
	 * @return
	 */
	public static JLabel lbInit() {
		JLabel merchandiseCode = new JLabel();
		merchandiseCode.setText("商品编号：");
		merchandiseCode.setBounds(64, 89, 68, 21);
		
		return merchandiseCode;
	}
	
	/**
	 * 输入框
	 */
	public static JTextField txfInit(InReturnGoodsDialog inReturnGoodsDialog) {
		JTextField merchandiseCode = new JTextField();
		merchandiseCode.setBounds(112, 50, 127, 21);
		merchandiseCode.addFocusListener(new FocusAdapter() {

			@Override
			public void focusLost(FocusEvent e) {
				JTextField jTextField1 = inReturnGoodsDialog.getTxfTime();
				JTextField txfMerchandiseCode = inReturnGoodsDialog.getTxfMerchandiseCode();
				JTextField jTextField4 = inReturnGoodsDialog.getJTextField4();
				
				if (jTextField1.getText().length() != 0) {
		            Vector select1 = Select_Means.Select_sort2(txfMerchandiseCode.getText());
		            Vector select2 = new Vector();
		            if (select1.size() == 0) {
		                JOptionPane.showMessageDialog(inReturnGoodsDialog, "商品不存在", "错误",
		                        JOptionPane.ERROR_MESSAGE);
		                return;
		            } else {
		                select2 = (Vector) select1.get(0);
		                Double pice=new Double(select2.get(4).toString());
		                double pice1=((int)(pice*100))/100.0;
		                Double pice2=new Double(pice1);
		                jTextField4.setText(pice2.toString()); //单价
		            }
		        }
			}
		});
		return merchandiseCode;
	}
}
